package es.uclm.itsue.SQLite;

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.content.Intent;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;

public class ItsueSQLiteActivity extends Activity {
    
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        
        BibliotecaSQLiteHelper bibHelper = new BibliotecaSQLiteHelper(this, "biblioteca.s3db", null, 2);
        SQLiteDatabase db = bibHelper.getReadableDatabase();
        
        Cursor c = db.rawQuery(" SELECT * FROM libros ", null);
        logCursorInfo(c);

        c = db.rawQuery(" SELECT * FROM lectores ", null);
        logCursorInfo(c);

        startActivity(new Intent(this,AdapterActivity.class));
        
        c.close();
        db.close();
        finish();
    }
    
    public void logCursorInfo(Cursor c) {
    	Log.i(getPackageName(), "*** Cursor begin ***   " + 
    			"filas:" + c.getCount() + 
    			"\tcolumnas:" + c.getColumnCount());
    	
		String rowHeaders = "";
    	for (int i=0; i<c.getColumnCount(); i++) {
    		rowHeaders = rowHeaders.concat(c.getColumnName(i) + "   ");
    	}
       	Log.i(getPackageName(), rowHeaders);
    	
    	while (c.moveToNext()) {
    		String rowData = "";
        	for (int i=0; i<c.getColumnCount(); i++) {
        		rowData = rowData.concat(c.getString(i) + "   ");
        	}
           	Log.i(getPackageName(), rowData);
    	} 
    }
}